<?php

namespace Apps\AppApi\Method\User;


use Apps\AppApi\Method\BaseMethod;
use Apps\Common\Models\UserFeedback;
use PhalconPlus\Api\Common\ResultStatus;

class Feedback extends BaseMethod
{
    public function run()
    {
        $content = trim($this->getDataItem('content', ''));
        $contact = $this->getDataItem('contact', '');
        $city_id = $this->getDataItem('city_id', '0');

        if(empty($content) || $this->utf8_strlen($content) > 500) {
            return $this->errorLog(ResultStatus::POST_BODY_PARAM_ERROR, '内容需在1-500字内');
        }
        $this->verifyUserAuth(false);
        $feedback = new UserFeedback();
        $feedback->user_id = $this->getUserAuth() ? $this->getUserAuth()->userId : 0;
        $feedback->feedback_content = $content;
        $feedback->feedback_contact = $contact;
        $feedback->city_id = $city_id;
        if($feedback->save()) {
            $this->setResult([
                'success' => 1,
                'message' => '反馈成功！'
            ]);
        } else {
            $this->databaseErrorLog($feedback);
        }
    }
}